﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HomeWork11
{
    public partial class Form1 : Form
    {
        public static String[,] words = new String[999, 2];
        public static int index = 0;
        public static int i = 0;
        public static int right = 0;
        public static int wrong = 0;
        public Form1()
        {
            InitializeComponent();
            String connetStr = "server=127.0.0.1;port=3306;user=root;password=111111; database=words;";
            MySqlConnection conn = new MySqlConnection(connetStr);
            string sql = "SELECT * FROM words.translation;";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            try
            {
                conn.Open();

                textBox1.Text = "单词库连接成功";
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    words[index, 1] = reader.GetString("english");
                    words[index, 0] = reader.GetString("chinese");
                    index += 1;
                }
                textBox2.Text = words[0, 0];
            }
            catch (MySqlException ex)
            {
                textBox1.Text = ex.Message;
            }
            finally
            {
                conn.Close();
            }
        }

        private void textBox3_KeyUp_1(object sender, KeyEventArgs e)
        {
           
            if (e.KeyCode == Keys.Control || e.KeyCode == Keys.Enter)
            {
                if (textBox3.Text == words[i, 1])
                {
                    textBox4.Text = "正确";
                    right ++;
                    textBox6.Text = right.ToString();
                }
                else
                {
                    textBox4.Text = "错误，正确答案是"+words[i,1];
                    wrong ++;
                    textBox7.Text = wrong.ToString();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox3.Text ="";
            textBox4.Text = "";
            i++;
            textBox2.Text = words[i, 0];
        }
    }

}